package me.keiwu.user.domain;

import lombok.Data;
import me.keiwu.pub.data.service.UserInfoBean;
import org.hibernate.annotations.ColumnDefault;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 * Created by kei on 02/02/2018.
 */
@Data
@Entity
@Table(indexes = {
        @Index(name = "idx_toUser", columnList = "toUser"),
        @Index(name = "idx_type", columnList = "noticeType"),
        @Index(name = "idx_key", columnList = "uniqueKey")
})
public class Notice {

    @Id
    @GeneratedValue
    private Long id;

    @ColumnDefault("0")
    @Column(columnDefinition = "TINYINT", nullable = false, length = 1)
    private Integer noticeType;

    private Long fromUser;

    // 需要通知的人
    private Long toUser;

    private Integer time;

    @ColumnDefault("0")
    @Column(columnDefinition = "TINYINT", length = 1, nullable = false)
    private boolean hasRead;

    // 附加信息
    /**
     * noticeType=0: addition表示金币数量
     * noticeType=1: addition表示json串，如：
     *  {"commentId":1, "message":"simple message"}
     *
     */
    private String addition;

    // 唯一key，用于搜索
    @Column(length = 16)
    private String uniqueKey;

    @Transient
    private UserInfoBean fromUserInfo;

    @Transient
    private UserInfoBean toUserInfo;

}
